/**
 * 
 */
package classe;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * @author guispeed4262
 *
 */
public class Facture  implements Comparable <Facture> {
	private Date date;
	private static int num=0,numAnnee=1;
	private int id,idAnnee;
	private ArrayList <Poste> poste;
	private double total;
	private String reference,holdReference;
	private int idClient,numListe;
	
	public Facture(int idClient,ArrayList <Poste> poste,String reference,Date date,String holdReference,int numListe){
		this.poste= new ArrayList <Poste>();
		this.poste.addAll(poste);
		this.reference=reference;		
		this.numAnnee++;
		this.id=this.num;
		this.idAnnee=this.numAnnee;
		this.idClient=idClient;
		this.numListe=num;
		this.num++;
		this.date=date;
		this.holdReference=holdReference;
		this.numListe=numListe;
	}
	public static String getNouvRef(){
		String str=""+Calendar.getInstance().get(Calendar.YEAR);
		str=str.substring(2,4);
		if(getNumAnnee() < 10){
			return str+"-0"+getNumAnnee();
		}else
		{
		return str+"-"+getNumAnnee();
		}
	}
	public int getIdAnnee() {
		return idAnnee;
	}
	public static int getNumAnnee() {
		return numAnnee;
	}
	public int getIdClient() {
		return idClient;
	}
	public String getReference() {
		return reference;
	}
	public Poste getPoste(int nbr){
		return poste.get(nbr);
	}

	public int getNbrPoste() {
		return poste.size();
	}
	
	public int getNumListe() {
		return numListe;
	}

	public double getTotalTTC(){
		double total=0.0;
		for(int i=0;i<poste.size();i++){
			total+=poste.get(i).getMontantTTC();
		}
		return total;
	}
	public String toString(){
		return idClient+" "+reference+" "+date.toString()+" "+holdReference;
	}
	public String getHoldReference() {
		return holdReference;
	}
	
	public void setNumListe(int numListe) {
		this.numListe = numListe;
	}
	public int compareTo(Facture fact){
		//if (this.reference.compareTo(dev.reference) ==0){
		System.out.println(this.reference.compareTo(fact.reference));
			return this.reference.compareTo(fact.reference);
		/*
		}else {
			return this.idClient.compareTo (dev.idClient);
		}
		*/
	}
	public boolean equals (Facture fact){
		if(this.holdReference ==fact.getHoldReference()){
			return true;
		}else 
			return false;		
	}
	
}
